package com.yogee.topseller.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.yogee.core.http.listener.HttpOnNextListener;
import com.yogee.core.http.subscribers.BaseSubscriber;
import com.yogee.core.utils.ToastUtils;
import com.yogee.topseller.R;
import com.yogee.topseller.activity.base.HttpActivity;
import com.yogee.topseller.activity.tianyan.GphqDetailActivity;
import com.yogee.topseller.activity.tianyan.SxrDetailActivity;
import com.yogee.topseller.adapter.DcdyAdapter;
import com.yogee.topseller.adapter.GqczAdapter;
import com.yogee.topseller.adapter.GrfxAdapter;
import com.yogee.topseller.adapter.XzcfAdapter;
import com.yogee.topseller.adapter.XzcfItemAdapter;
import com.yogee.topseller.adapter.ZqxxListAdapter;
import com.yogee.topseller.bean.DcdyBean;
import com.yogee.topseller.bean.GqczBean;
import com.yogee.topseller.bean.GrfxBean;
import com.yogee.topseller.bean.HuiyuanListModel;
import com.yogee.topseller.bean.XwzxBean;
import com.yogee.topseller.bean.XzcfBean;
import com.yogee.topseller.bean.ZqxxBean;
import com.yogee.topseller.http.HttpManager;
import com.yogee.topseller.layout.TitleLayout;
import com.yogee.topseller.utils.AppUtil;
import com.yogee.topseller.utils.Constants;
import com.yogee.topseller.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 行政处罚
 * Created by Administrator on 2018/5/14.
 */

public class XzcfActivity extends HttpActivity {
    @BindView(R.id.title)
    TitleLayout title;
    @BindView(R.id.rv_xzcf)
    RecyclerView rv_xzcf;
    List<XzcfBean.Item> list = new ArrayList<>();

    XzcfItemAdapter xzcfAdapter;
    GrfxAdapter grfxAdapter;
    ZqxxListAdapter zqxxListAdapter;
    GqczAdapter gqczAdapter ;
    DcdyAdapter dcdyAdapter;

    private String type="";
    private String companyId= "";
    String cmpanyType="";
    private String proId="";
    @Override
    protected int getLayoutId() {
        return R.layout.activity_xzcf;
    }

    @Override
    protected void initView() {
        type = getIntent().getStringExtra("type");
        title.setTitle(getIntent().getStringExtra("title"));
        companyId = getIntent().getStringExtra("companyId");
        cmpanyType = getIntent().getStringExtra("cmpanyType");
        proId = getIntent().getStringExtra("proId");
        title.setActivity(this);
        rv_xzcf.setLayoutManager(new LinearLayoutManager(this));

        // 行政处罚
        if(type.equals(Constants.EyeCheck_XZRF_TYPE)){
            LogUtils.e("soso","行政处罚");
            xzcfAdapter = new XzcfItemAdapter(this);
            rv_xzcf.setAdapter(xzcfAdapter);
//            xzcfAdapter.addData((List<XzcfBean.Item>) getIntent().getSerializableExtra("info"));
            initXzcf();
        // 个人风险
        }else if(type.equals(Constants.EyeCheck_RFX_TYPE)){
            grfxAdapter = new GrfxAdapter(this);
            rv_xzcf.setAdapter(grfxAdapter);
//            grfxAdapter.addData((List<GrfxBean.Item>) getIntent().getSerializableExtra("info"));
            initGrfx();
            // 债券信息
        }else if(type.equals(Constants.EyeCheck_ZJXX_TYPE)){
            zqxxListAdapter = new ZqxxListAdapter(this);
            rv_xzcf.setAdapter(zqxxListAdapter);
//            zqxxListAdapter.addData((List<ZqxxBean.Item>) getIntent().getSerializableExtra("info"));
            initZqxx();
            // 股权出质
        }else if(type.equals(Constants.EyeCheck_GQCZ_TYPE)){
            gqczAdapter = new GqczAdapter(this);
            rv_xzcf.setAdapter(gqczAdapter);
//            gqczAdapter.addData((List<GqczBean.Item>) getIntent().getSerializableExtra("info"));
            initGqcz();
            // 动产抵押
        }else  if(type.equals(Constants.EyeCheck_DCDY_TYPE)){
            dcdyAdapter = new DcdyAdapter(this);
            rv_xzcf.setAdapter(dcdyAdapter);
//            dcdyAdapter.addData((List<DcdyBean.Item>) getIntent().getSerializableExtra("info"));
            initDcdy();
        }
    }

    /**
     * 行政处罚
     */
    private void initXzcf(){
        HttpManager.getInstance().eyeCheckXZCF(companyId,type, AppUtil.getUserId(XzcfActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<XzcfBean>() {
            @Override
            public void onNext(XzcfBean o) {
               if(o.getEyeCheck().getError_code()==0){
                   xzcfAdapter.addData(o.getEyeCheck().getResult().getItems());
               }else{
                   ToastUtils.showToast(XzcfActivity.this,o.getEyeCheck().getReason());
               }

            }
        }, this));
    }

    /**
     * 个人风险
     */
    private void initGrfx(){
        HttpManager.getInstance().eyeCheckGrfx(companyId,type, AppUtil.getUserId(XzcfActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GrfxBean>() {
            @Override
            public void onNext(GrfxBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    grfxAdapter.addData(o.getEyeCheck().getResult().getExternalList());
                }else{
                    ToastUtils.showToast(XzcfActivity.this,o.getEyeCheck().getReason());
                }

            }
        }, this));
    }

    /**
     * 债券信息
     */
    private void initZqxx(){
        HttpManager.getInstance().eyeCheckZqxx(companyId,type, AppUtil.getUserId(XzcfActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<ZqxxBean>() {
            @Override
            public void onNext(ZqxxBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    zqxxListAdapter.addData(o.getEyeCheck().getResult().getItems());
                }else{
                    ToastUtils.showToast(XzcfActivity.this,o.getEyeCheck().getReason());
                }
            }
        }, this));
    }

    /**
     * 股权出质
     */
    private void initGqcz(){
        HttpManager.getInstance().eyeCheckGqcz(companyId,type, AppUtil.getUserId(XzcfActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<GqczBean>() {
            @Override
            public void onNext(GqczBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    gqczAdapter.addData(o.getEyeCheck().getResult().getItems());
                }else{
                    ToastUtils.showToast(XzcfActivity.this,o.getEyeCheck().getReason());
                }
            }
        }, this));
    }
    /**
     * 动产抵押
     */
    private void initDcdy(){
        HttpManager.getInstance().eyeCheckDcdy(companyId,type, AppUtil.getUserId(XzcfActivity.this),cmpanyType,proId).compose(this.bindRecycler()).subscribe(new BaseSubscriber(new HttpOnNextListener<DcdyBean>() {
            @Override
            public void onNext(DcdyBean o) {
                if(o.getEyeCheck().getError_code()==0){
                    dcdyAdapter.addData(o.getEyeCheck().getResult().getItem());
                }else{
                    ToastUtils.showToast(XzcfActivity.this,o.getEyeCheck().getReason());
                }
            }
        }, this));
    }
}
